package com.wgke.bluetooth.db;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface CmdDao {

    @Query("SELECT * FROM cmdEntity")
    List<CmdEntity> getAll();

    // 根据type查询命令列表
    @Query("SELECT * FROM cmdEntity WHERE type = :type")
    List<CmdEntity> getCmdEntitiesByType(int type);

    // 根据type删除命令
    @Query("DELETE FROM cmdEntity WHERE type = :type")
    void deleteByType(int type);

    // 根据type和projectId联合查询
    @Query("SELECT * FROM cmdEntity WHERE type = :type AND projectId = :projectId")
    List<CmdEntity> getByTypeAndProjectId(int type, int projectId);

    // 根据type和projectId联合删除
    @Query("DELETE FROM cmdEntity WHERE type = :type AND projectId = :projectId")
    void deleteByTypeAndProjectId(int type, int projectId);

    // 获取最新添加的N条记录
    @Query("SELECT * FROM cmdEntity ORDER BY time DESC LIMIT :limit")
    List<CmdEntity> getRecentCommands(int limit);

    // 按projectId操作 - 新增功能
    @Query("SELECT * FROM cmdEntity WHERE projectId = :projectId")
    List<CmdEntity> getByProjectId(int projectId);

    @Query("DELETE FROM cmdEntity WHERE projectId = :projectId")
    void deleteByProjectId(int projectId);

    @Query("DELETE FROM cmdEntity")
    void deleteAll();

    @Insert
    void insertAll(CmdEntity... users);

    @Delete
    void delete(CmdEntity user);

    @Update
    void update(CmdEntity user);
}
